package com.fit.pages;

import org.apache.tapestry5.annotations.InjectPage;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.annotations.SessionState;
import org.apache.tapestry5.ioc.annotations.Inject;

import com.fit.interfaces.Car;
import com.fit.interfaces.User;
import com.fit.service.Cars;

public class ViewCar {

	@Inject
	@Property
	private Cars cars;
	
	@Property
	private Car chosenCar;
	
	//-----------------------------------
	
	@InjectPage
	private CarDetails carDetailsPage;
	
	@InjectPage
	private EntryBorrow entryBorrow;
	
	@SessionState
	private User user;
	
	private boolean userExists;
	
	Object onActivate(){
		if(!userExists) return Login.class;
		return null;
	}

	public User getUser() {
		return user;
	}
	
	@OnEvent(component = "carDetailsPage")
	Object onActionLink(String modelName){
		Car chosen = cars.retriveSingleCar(modelName);
		carDetailsPage.setChosenCar(chosen);
		return carDetailsPage;
	}

	@OnEvent(component = "entryCarLink")
	Object onEntryLink(String modelName){
		entryBorrow.setBorrowCar(modelName);
		return entryBorrow;
	}
	//-----------------------------
	
	
}
